package com.deer.wms.base.system.web.carArea;

import com.deer.wms.base.system.model.ware.CarArea;
import com.deer.wms.base.system.model.ware.Supplier;
import com.deer.wms.base.system.service.ware.ICarAreaService;
import com.deer.wms.common.annotation.Log;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.enums.BusinessType;
import com.deer.wms.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 月台管理
 */
@Controller
@RequestMapping("/carArea")
public class CarAreaController extends BaseController {
    private String prefix = "carArea";
    @Autowired
    private ICarAreaService carAreaService;

    @RequiresPermissions("carArea:view")
    @GetMapping("/page")
    public String carArea()
    {
        return prefix + "/carArea";
    }

    /**
     * 查询月台列表
     * @return
     */
    @RequiresPermissions("carArea:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CarArea carArea){
        startPage();
        List<CarArea> list = carAreaService.list(carArea);
        return getDataTable(list);
    }

    /**
     * 查询空闲月台
     * @param carArea
     * @return
     */
    @RequestMapping("/selectNullStateList")
    @ResponseBody
    public List<CarArea> selectNullStateList(CarArea carArea){
        List<CarArea> list = carAreaService.selectNullStatelist(carArea);
        return list;
    }

    /**
     * 导出月台列表
     */
    @RequiresPermissions("carArea:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CarArea carArea)
    {
        List<CarArea> list = carAreaService.list(carArea);
        ExcelUtil<CarArea> util = new ExcelUtil<>(CarArea.class);
        return util.exportExcel(list, "月台列表");
    }

    /**
     * 新增月台
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存月台
     */
    @RequiresPermissions("carArea:add")
    @Log(title = "月台", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CarArea carArea)
    {
        carArea.setCarState(0);//初始化为空闲状态
        return toAjax(carAreaService.insertCarArea(carArea));
    }

    /**
     * 修改月台
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        CarArea carArea = carAreaService.selectCarAreaById(id);
        mmap.put("carArea", carArea);
        return prefix + "/edit";
    }

    /**
     * 修改保存月台
     */
    @RequiresPermissions("carArea:edit")
    @Log(title = "月台", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CarArea carArea)
    {
        return toAjax(carAreaService.updateCarArea(carArea));
    }

    /**
     * 删除月台
     */
    @RequiresPermissions("carArea:delete")
    @Log(title = "月台", businessType = BusinessType.DELETE)
    @PostMapping( "/delete")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(carAreaService.deleteCarAreaByIds(ids));
    }

}
